package com.neusoft.yuejian_6.activity;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;

import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.adapter.InformAdapter;
import com.neusoft.yuejian_6.javabean.Inform;
import com.neusoft.yuejian_6.model.UserModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class InformActivity extends Activity {

    private ImageView back;
    private int user_id;
    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_inform);
        initViews();//初始化
        initData();//点击事件处理
        initEvent();
    }

    private void initViews() {
        recyclerView = (RecyclerView) findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局

        back=(ImageView) findViewById(R.id.back);
    }



    public void initEvent() {
        back.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                finish();
            }
        });}



    private void initData() {
        SharedPreferences sp = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        user_id = sp.getInt("user_id", 0);
        //   Log.d("we","user_id");

        UserModel userModel = new UserModel();
        //发送请求
        Call<List<Inform>> call = userModel.getinformlist
                (user_id);
        //2.处理结果
        call.enqueue(new Callback<List<Inform>>() {
            @Override
            public void onResponse(Call<List<Inform>> call, Response<List<Inform>> response) {
                List<Inform> data = (List<Inform>) response.body();  //获取数据
                recyclerView.setAdapter(new InformAdapter(InformActivity.this, data));
            }

            @Override
            public void onFailure(Call<List<Inform>> call, Throwable t) {

            }

        });
    }



}
